package com.taxi.apipassenger.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author: Ruomeng
 * @Date: 2023/11/10
 * @Description : online-taxi
 * @Version: 1.0
 */
@RestController
@RequestMapping("/instance-check")
public class InstanceCheckController {

    @Autowired
    DiscoveryClient discoveryClient;

    @GetMapping("/check")
    public String check() {
        List<String> services = discoveryClient.getServices();
        for (String serviceName : services) {
            List<ServiceInstance> instances = discoveryClient.getInstances(serviceName);
            for (ServiceInstance instance : instances) {
                System.out.println(instance.getServiceId());
                System.out.println(instance.getMetadata().get("name"));
                System.out.println(instance.getMetadata().get("version"));
            }
        }
        return "success";
    }

}
